<template>
  <u-popup :show="show" round="10px" @close="cancel" :closeOnClickOverlay="true" :closeable="true" mode="bottom">
    <div class="post_demand_popup">
      <div class="title">请选择您的需求</div>
      <div class="content">
        <div class="wrap wrap1">
          <button
            class="item_btn"
            v-if="(!getUserInfo && getUserStatus && !getUserStatus.job_status) || !getUserStatus"
            open-type="getPhoneNumber"
            @getphonenumber="getPhoneNumber1"
          >
            <image src="@/static/images/common/fbzp.png" mode="scaleToFill" />
            <p>发布招聘</p>
          </button>
          <div class="item" v-else-if="getUserInfo && getUserStatus && !getUserStatus.job_status" @click="clickItem(1, 'fb')">
            <image src="@/static/images/common/fbzp.png" mode="scaleToFill" />
            <p>发布招聘</p>
          </div>
          <div class="item" v-else-if="getUserInfo && getUserStatus && getUserStatus.job_status" @click="clickItem(1, 'gl')">
            <image src="@/static/images/common/fbzp.png" mode="scaleToFill" />
            <p>管理招聘</p>
          </div>
          <button
            class="item_btn"
            v-if="(!getUserInfo && getUserStatus && !getUserStatus.resume_status) || !getUserStatus"
            open-type="getPhoneNumber"
            @getphonenumber="getPhoneNumber2"
          >
            <image src="@/static/images/common/fbqz.png" mode="scaleToFill" />
            <p>发布求职</p>
          </button>
          <div class="item" v-else-if="getUserInfo && getUserStatus && !getUserStatus.resume_status" @click="clickItem(2, 'fb')">
            <image src="@/static/images/common/fbqz.png" mode="scaleToFill" />
            <p>发布求职</p>
          </div>
          <div class="item" v-else-if="getUserInfo && getUserStatus && getUserStatus.resume_status" @click="clickItem(2, 'gl')">
            <image src="@/static/images/common/fbqz.png" mode="scaleToFill" />
            <p>管理求职</p>
          </div>
        </div>
        <div class="wrap">
          <button
            class="item_btn"
            v-if="(!getUserInfo && getUserStatus && !getUserStatus.storefront_status) || !getUserStatus"
            open-type="getPhoneNumber"
            @getphonenumber="getPhoneNumber3"
          >
            <image src="@/static/images/common/zzzd2.png" mode="scaleToFill" />
            <p>发布转店</p>
          </button>
          <div class="item" @click="clickItem(3, 'gl')" v-else-if="getUserInfo && getUserStatus && getUserStatus.storefront_status">
            <image src="@/static/images/common/zzzd2.png" mode="scaleToFill" />
            <p>管理转店</p>
          </div>
          <div class="item" @click="clickItem(3, 'fb')" v-else>
            <image src="@/static/images/common/zzzd2.png" mode="scaleToFill" />
            <p>发布转店</p>
          </div>


          <button
            class="item_btn"
            v-if="(!getUserInfo && getUserStatus && !getUserStatus.storefront_status) || !getUserStatus"
            open-type="getPhoneNumber"
            @getphonenumber="getPhoneNumber3"
          >
            <image src="@/static/images/common/cyfw.png" mode="scaleToFill" />
            <p>餐饮服务</p>
          </button>
          <div class="item" @click="clickItem(5, 'gl')" v-else-if="getUserInfo && getUserStatus && getUserStatus.storefront_status">
            <image src="@/static/images/common/cyfw.png" mode="scaleToFill" />
            <p>服务管理</p>
          </div>
          <div class="item" @click="clickItem(5, 'fb')" v-else>
            <image src="@/static/images/common/cyfw.png" mode="scaleToFill" />
            <p>餐饮服务</p>
          </div>
        </div>
      </div>
    </div>
  </u-popup>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  name: "postDemand",
  props: {
    show: {
      type: Boolean,
      default: true,
    },
    isrefresh: {
      type: Object,
    },
  },
  data() {
    return {
      isLogin: false,
      phone: "",
      userStatus: null, //resume_status,job_status
    };
  },
  computed: {
    ...mapGetters("user", ["getUserInfo", "getUserStatus"]),
    // getUserStatus() {
    //   if (this.isrefresh) {
    //     this.setStatus();
    //   }
    //   return this.userStatus;
    // },
  },
  methods: {
    ...mapActions("user", ["setUserInfo", "setStatus", "chatLogin"]),
    async submit() {
      this.$emit("submit");
    },
    cancel() {
      this.$emit("cancel");
    },
    clickItem(type, type2) {
      switch (type) {
        case 1:
          if (type2 == "gl") {
            this.$togo("/pages2/regulateJobs");
          } else {
            this.$togo("/pages2/postOffer", { phone: this.phone });
          }
          this.$emit("cancel");
          break;
        case 2:
          if (type2 == "gl") {
            this.$togo("/pages2/regulateResume");
          } else {
            this.$togo("/pages2/postRecruitmentInformation", { phone: this.phone });
          }
          this.$emit("cancel");
          break;
        case 3:
          if (type2 == "gl") {
            this.$togo("/shopPackage/manageStore");
          } else {
            this.$togo("/shopPackage/publishStore");
          }
          this.$emit("cancel");
          break;
        case 4:
          this.$layer.message("功能正在开发中,敬请期待...");
          break;
        case 5:
          if (type2 == "gl") {
            this.$togo("/restaurantService/manageService");
          } else {
            this.$togo("/restaurantService/publishService");
          }
          this.$emit("cancel");
          break;
      }
    },
    async getPhoneNumber1(e) {
      let _this = this;
      let deviceModel = await this.getSysteminfo();

      if (e.detail.errMsg == "getPhoneNumber:ok") {
        let res = await _this.chatLogin({ code: e.detail.code, deviceModel: deviceModel, type: "job" });
        if (res) {
          _this.isLogin = true;
          _this.phone = res.phone;
          console.log(this.setStatus);
          let state = await _this.setStatus();
          if (state) {
            if (_this.getUserStatus.job_status) {
              _this.$togo("/pages2/regulateJobs");
            } else {
              _this.$togo("/pages2/postOffer", {
                phone: res.phone,
              });
            }
            setTimeout(() => {
              _this.$emit("reload");
            }, 1000);
          }
        }
      } else {
        this.$togo("/pages2/postOffer");
      }
    },
    async getPhoneNumber2(e) {
      let _this = this;
      let deviceModel = await this.getSysteminfo();
      if (e.detail.errMsg === "getPhoneNumber:ok") {
        let res = await _this.chatLogin({ code: e.detail.code, deviceModel: deviceModel, type: "resume" });
        console.log("res161", res);
        if (res) {
          _this.isLogin = true;
          _this.phone = res.phone;
          console.log(this.setStatus);
          let state = await _this.setStatus();
          if (state) {
            if (_this.getUserStatus.job_status) {
              _this.$togo("/pages2/regulateResume");
            } else {
              _this.$togo("/pages2/postRecruitmentInformation", {
                phone: res.phone,
              });
            }
            setTimeout(() => {
              _this.$emit("reload");
            }, 1000);
          }
        }
      } else {
        this.$togo("/pages2/postRecruitmentInformation");
      }
    },
    async getPhoneNumber3(e) {
      let _this = this;
      let deviceModel = await this.getSysteminfo();
      if (e.detail.errMsg === "getPhoneNumber:ok") {
        let res = await _this.chatLogin({ code: e.detail.code, deviceModel: deviceModel, type: "storefront" });
				if (res) {
          _this.isLogin = true;
          _this.phone = res.phone;
          let state = await _this.setStatus();
          if (state) {
            if (_this.getUserStatus.storefront_status) {
              _this.$togo("/shopPackage/manageStore");
            } else {
              _this.$togo("/shopPackage/publishStore");
            }
            setTimeout(() => {
              _this.$emit("reload");
            }, 1000);
          }
        }
      } else {
        this.$togo("/shopPackage/publishStore");
      }
    },
    getSysteminfo() {
      return new Promise(resolve => {
        uni.getSystemInfo({
          success: res => {
            this.device_model = res.deviceModel;
            resolve(res.deviceModel);
          },
        });
      });
    },
  },
  watch: {},
  created() {
    if (this.$getStoraged("phone")) {
      this.isLogin = true;
      this.phone = this.$getStoraged("phone");
    } else {
      this.isLogin = false;
    }
    this.setStatus();
  },
  // 组件周期函数--监听组件挂载完毕
  mounted() {},
  // 组件周期函数--监听组件数据更新之前
  beforeUpdate() {},
  // 组件周期函数--监听组件数据更新之后
  updated() {},
  // 组件周期函数--监听组件激活(显示)
  activated() {},
  // 组件周期函数--监听组件停用(隐藏)
  deactivated() {},
  // 组件周期函数--监听组件销毁之前
  beforeDestroy() {},
};
</script>

<style scoped lang="scss">
.post_demand_popup {
  height: 324px;
  box-sizing: border-box;
  padding: 15px 21px;
  text-align: center;
  .title {
    font-size: 16px;
    font-family: PingFang SC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
  }
  .content {
    margin: 24px auto 0;
    .wrap {
      display: flex;
      justify-content: space-around;
      margin-bottom: 30px;
      .item {
        image {
          width: 71px;
          height: 71px;
        }
        ._p {
          font-size: 14px;
          font-family: PingFang SC-Regular, PingFang SC;
          font-weight: 400;
          color: #333333;
        }
      }
      .item_btn {
        width: 71px;
        height: 95px;
        border: none;
        background: transparent;
        padding: 0;
        margin: 0;
        image {
          width: 71px;
          height: 71px;
        }
        ._p {
          font-size: 14px;
          font-family: PingFang SC-Regular, PingFang SC;
          font-weight: 400;
          color: #333333;
          margin-top: -22px;
        }
        &::after {
          content: "";
          border: none;
          box-shadow: none;
        }
      }
    }
    .wrap1 {
      width: 70%;
      margin: 0 auto;
      margin-bottom: 30px;
    }
  }
}
</style>
